package com.chris.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.chris.bean.User;
import com.chris.service.impl.UserManageImpl;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private UserManageImpl userManage;
	private User user;
	private List<User> userList;
	private String method;

	public String findUser() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String gid = (String) request.getParameter("id");
		int id = 0;
		if (gid != null && !"".equals(gid)) {
			id = Integer.parseInt(gid);
		}
		user = this.userManage.findByUserId(id);
		System.out.println("find");
		return "jsons";
	}

	public String save() {
		try {
			this.userManage.insert(user);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "index";
	}

	public String findAll() {
		try {
			userList = this.userManage.findAllUser("");
			System.out.println("size: " + userList.size());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "show";
	}

	public void setUserManage(UserManageImpl userManage) {
		this.userManage = userManage;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

}
